﻿using IntelligentAgriculture.Contracts.Interface;
using IntelligentAgriculture.Domain.Entity;
using IntelligentAgriculture.Services;
using IntelligentAgriculture.WebAPI.Application.Command.DeathModelCommand;
using IntelligentAgriculture.WebAPI.Application.Command.RidgepCpoamd;
using MediatR;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;

namespace IntelligentAgriculture.WebAPI.Application.CommandHandler.DeathModelCommandJamdier
{
    public class DeathEagAddCommandHandler : IRequestHandler<DeathEagAddCommand,Results<int>>
    {
        private readonly iDeathModelService _iDeathModelService;

        public DeathEagAddCommandHandler(iDeathModelService deathModelService)
        {
            _iDeathModelService = deathModelService;
        }



        public async Task<Results<int>> Handle(DeathEagAddCommand request, CancellationToken cancellationToken)
        {
            try
            {
                
                var result = await _iDeathModelService.Add(request.deathmodels);
                return Results<int>.DataResult(result);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error adding DeathModel: {ex.Message}");
                throw;
            }
        }
    }
}
